﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zcu.PanelComposer.ViewModels.Events;
using Caliburn.Micro;
using System.ComponentModel.Composition;
using Zcu.PanelComposer.Interfaces;

namespace Zcu.PanelComposer.ViewModels.Core
{
    /// <summary>
    /// Potomek obrazovky z Caliburn.Micro frameworku.
    /// Implementace prechodu mezi strankami/moduly.
    /// </summary>
    public abstract class NavigateScreen : Screen, IModule
    {
        #region Properties

        /// <summary>
        /// Zdali ma byt modul skryt v menu.
        /// </summary>
        public bool MenuVisible { set; get; }

        /// <summary>
        /// Stranka, ze ktere bylo zavolano presmerovani.
        /// </summary>
        public PageNames SourcePage { get; set; }

        /// <summary>
        /// Nazev modulu. 
        /// Bude pouzit pro navigaci po aplikaci.
        /// </summary>
        public PageNames ModuleName { get; protected set; }

        /// <summary>
        /// Poradi v menu.
        /// </summary>
        public int Order { get; protected set; }

        /// <summary>
        /// Objekt, ktery je predavany pri navigaci.
        /// </summary>
        public object Context { get; set; }

        /// <summary>
        /// Reference na event aggregator.
        /// </summary>
        [Import]
        public IEventAggregator EventAggregator { get; set; }

        #endregion // Properties

        #region Constructor

        /// <summary>
        /// Konstruktor, ktery prednastavuje defaultni hodnoty modulum.
        /// </summary>
        public NavigateScreen()
        {
            MenuVisible = true;
        }

        #endregion // Constructor

        #region Event methods

        /// <summary>
        /// Udalost, ktera je volana hned po vytvoreni screenu.
        /// </summary>
        public virtual void OnReconstruct() { }

        #endregion // Event methods

        #region Navigate methods

        /// <summary>
        /// Pomocna metoda, ktera slouzi pro navigaci po strankach.
        /// </summary>
        /// <param name="name">Jmeno stranky</param>
        protected virtual void Navigate(PageNames name)
        {
            EventAggregator.Publish(new NavigateEvent(ModuleName, name));
        }

        /// <summary>
        /// Pomocna metoda, ktera slouzi pro navigaci po strankach.
        /// </summary>
        /// <param name="name">Jmeno stranky</param>
        /// <param name="context">predavany objekt</param>
        protected virtual void Navigate(PageNames name, object context)
        {
            EventAggregator.Publish(new NavigateEvent(ModuleName, name, context));
        }

        #endregion // Navigate methods
    }
}
